package edu.wpi.first.wpilibj.sensor;
import edu.wpi.first.wpilibj.AnalogChannel;
import edu.wpi.first.wpilibj.frc.Robot;
import edu.wpi.first.wpilibj.positioning.PositionHandler;
/**
 * This is a class to represent the potentiometer on the bot. It stores its position as a PositionHandler.
 * @author Gaughan
 */
public class Potentiometer extends AnalogChannel {
    private PositionHandler PH = new PositionHandler(Robot.robot.currentField);     
    public Potentiometer(int moduleNumber, int channel) {
        super(moduleNumber, channel);
        Robot.robot.addTicker(new Runnable() {
            @Override
            public void run() {
                PH.updateRotation(converttodegrees(getValue()), 0, 0);               
            }
        });
    }
    
    public Potentiometer(int channel) {
        super(channel);
        Robot.robot.addTicker(new Runnable() {
            @Override
            public void run() {
                PH.updateRotation(converttodegrees(getValue()), 0, 0);               
            }
        });
    }    
    
    private double converttodegrees(int value){
        if (value == 1000){
            value = 0;
        }
        value *= 0.36;
        value -= 180;
        return value;
    }
    public double getDegrees(){
        return PH.getPitch();
        }
}